﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using AppToolkit.WPF.Controls;
using AppToolkit.WPF.Utils;
using NUnit.Framework;
using UnitTestUtils.UI;

namespace AppToolkit.WPF.Tests.Controls
{
    [TestFixture]
    public class ImageButtonNonShaderTests
    {
        UIHost _host;
        Button _target;

        #region Setup / Teardown
        [SetUp]
        public void Setup()
        {
            this._target = new ImageButton();
            this._target.Width = 200;
            this._target.Height = 200;



            this._host = UIHost.Create(this._target);
        }

        [TearDown]
        public void Dispose()
        {
            this._target = null;
            this._host = null;
            UnitTestUtils.UI.UITestHelper.CleanupDispatcher();
        }
        #endregion

        [Test, RequiresSTA]
        public void InteractiveTest_real_Exception()
        {
            this._host.Show();

            var rd = new ResourceDictionary();
            rd.Source = PackUriHelper.From(typeof(PackUriHelper), "Controls/ImageButtonStyle.xaml");
            this._host.Window.Resources.MergedDictionaries.Add(rd);

            this._target.Style = (Style)this._host.Window.Resources["ImageButtonStyle"];

            var img = new Image();
            img.Width = 190;

            img.Source = BitmapHelper.CreateTestImage();
            this._target.Content = img;

            var timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(2);
            timer.Tick += (s, a) =>
                              {
                                  this._target.IsEnabled = !this._target.IsEnabled;
                              };
            timer.Start();

            this._host.WaitForClose();
        }
    }
}